# encoding: utf-8
# author: walker
# date: 2018-01-31
# summary: 接收方/消费者

import pika


# 接收处理消息的回调函数
def ConsumerCallback(channel, method, properties, body):
    print("Received %s" % body)


def Main():
    credentials = pika.PlainCredentials("cluster-ms-cmall", "cluster-ms-cmall")
    parameters = pika.ConnectionParameters(host="10.129.83.213", virtual_host='/backup', credentials=credentials)
    connection = pika.BlockingConnection(parameters)
    channel = connection.channel()
    queue = channel.queue_declare(queue='accountroom.change.queue', durable=True)

    # no_ack=True 开启自动确认，不然消费后的消息会一直留在队列里面
    # no_ack = no_manual_ack = auto_ack；不手动应答，开启自动应答模式
    channel.basic_consume(on_message_callback=ConsumerCallback, queue='accountroom.change.queue', auto_ack=True)
    print('Wait Message ...')

    channel.start_consuming()


if __name__ == '__main__':
    Main()
